package com.zju.iotplant.util;


import java.io.Serializable;

/**
 * ResponseBody注解返回的JSON对象类
 */
public class ResponseResult<T> implements Serializable {

    private int code = 0;

    private String msg = "";

    private String detailMsg = "";

    private T data;

    public ResponseResult(int code, String msg, String detailMsg, T data) {
        this.code = code;
        this.msg = msg;
        this.detailMsg = detailMsg;
        this.data = data;
    }

    public static <U> ResponseResult success() {
        return build(0, "success", "", "");
    }

    public static <U> ResponseResult success(final U data) {
        return build(0, "", "", data);
    }

    public static ResponseResult failure(final String msg) {
        return failure(-1, msg, "");
    }

    public static ResponseResult failure() {
        return failure(-1, "", "");
    }

    public static ResponseResult failure(final String msg, final String detailMsg) {
        return failure(-1, msg, detailMsg);
    }

    public static ResponseResult failure(final int code, final String msg, final String detailMsg) {
        return build(code, msg, detailMsg, null);
    }


    public static <U> ResponseResult build(final int code, final String msg, final String detailMsg, final U data) {
        return new ResponseResult<>(code, msg, detailMsg, data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getDetailMsg() {
        return detailMsg;
    }

    public void setDetailMsg(String detailMsg) {
        this.detailMsg = detailMsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
